package cn.tedu.ivos2.vehicle.controller;

import cn.tedu.ivos2.base.response.JsonResult;
import cn.tedu.ivos2.vehicle.pojo.dto.VehicleParam;
import cn.tedu.ivos2.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos2.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos2.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/v1/vehicle")
public class VehicleController {
    @Autowired
    VehicleService vehicleService;

    @GetMapping("select")
    public JsonResult selectVehicle(VehicleQuery vehicleQuery) {
        log.debug("查询车辆:{}",vehicleQuery);
        List<VehicleVO> list = vehicleService.selectVehicle(vehicleQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult saveVehicle(VehicleParam vehicleParam) {
        log.debug("新增车辆,{}",vehicleParam);
        vehicleService.saveVehicle(vehicleParam);
        return JsonResult.ok();
    }

    @PostMapping("/delete/{id}")
    public JsonResult deleteVehicle(@PathVariable Long id){
        log.debug("删除车辆,{}", id);
        vehicleService.deleteVehicle(id);
        return JsonResult.ok();
    }

    @PostMapping("unbind/{vehicleId}")
    public JsonResult unbind(@PathVariable Long vehicleId){
        log.debug("移除绑定车辆,{}", vehicleId);
        vehicleService.unBindVehicle(vehicleId);
        return JsonResult.ok();
    }

    @PostMapping("bind/{geofenceId}/{vehicleId}")
    public JsonResult bindVehicle(@PathVariable Long geofenceId, @PathVariable Long vehicleId){
        log.debug("绑定车辆:geofenceId={},vehicleId={}",geofenceId,vehicleId);
        vehicleService.bindVehicle(geofenceId,vehicleId);
        return JsonResult.ok();
    }

}
